﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace HA.ModFlow.Domain.DomainLayer
{

    /// <summary>
    /// 用于表示外围网格线所组成的三维网格数据,采用地下水的网格定义系统，
    /// 沿着Z轴正方向向下俯视（水平向右为X正方向，水平向上为Y轴正方向），三维网格左上角为0,0,0 点（指的是 I J K 而不是坐标原点，坐标原点在左下角方向），
    /// i表示row的变化 j表示col 的变化 ,k 表示垂直网格数
    /// 
    /// </summary>
    [Serializable]
    public class BoundGrid
    {
        #region 构造函数

        /// <summary>
        /// 
        /// </summary>
        /// <param name="i">行数（Rows外围边框上点）</param>
        /// <param name="j">列数</param>
        /// <param name="k">层数</param>
        public BoundGrid(int i, int j, int k)
        {
            _gridPoints = new Point3D[i, j, k];

        }

        #endregion


        #region 字段属性

        /// <summary>
        /// 内部表示的三维数组
        /// </summary>
        Point3D[, ,] _gridPoints;

        /// <summary>
        /// 第一表示i ,第二表示j ,第三表示k
        /// </summary>
        public Point3D[, ,] GridPoints
        {
            get { return _gridPoints; }

        }


        /// <summary>
        /// 有待测试  （Rows外围边框上点）
        /// </summary>
        public int RowsCount
        {
            get
            {

                return _gridPoints.GetLength(0);
            }
        }

        /// <summary>
        /// 外围边框上点
        /// </summary>
        public int ColumnsCount
        {
            get
            {
                return _gridPoints.GetLength(1);
            }
        }

        /// <summary>
        /// 外围边框上点个数
        /// </summary>
        public int LayersCount
        {
            get
            {

                return _gridPoints.GetLength(2);
            }
        }

        #endregion



        #region 外部方法

        
        /// <summary>
        /// 取得指定层Layer(体单元)中心所在的面的边框点的数据信息
        /// </summary>
        /// <param name="layerIndex"></param>
        /// <returns></returns>
        public Point3D[,] GetLayerBound(int layerIndex)
        {
            if (this._gridPoints ==null )
            {
                return null;
            }

            if (0 <= layerIndex && layerIndex < LayersCount - 1)
            {
                //存储找到的指定层的数据（包括边框）

                Point3D[,] layerBound=new Point3D [RowsCount ,ColumnsCount ];

                Point3D point3D1 = new Point3D();
                Point3D point3D2 = new Point3D();

                Point3D point = new Point3D();

                for (int rows  = 0; rows  < this.RowsCount ; rows ++)
                {
                    for (int cols  = 0; cols  < this.ColumnsCount ; cols ++)
                    {
                        
                        //取得层的上   下表面的点信息 求均值

                        //该方法有待测试  哈哈

                        point3D1 = this.GridPoints[rows, cols, layerIndex];

                        point3D2 = this.GridPoints[rows, cols, layerIndex+1];
            
                        point.X = (point3D1.X + point3D2.X) / 2;
                        point.Y = (point3D1.Y + point3D2.Y) / 2;
                        point.Z = (point3D1.Z + point3D2.Z) / 2;

                        layerBound[rows, cols] = new Point3D(point .X,point .Y ,point .Z );

                        //layerBound[rows, cols].X  = point.X ;
                        //layerBound[rows, cols].Y  = point.Y ;
                        //layerBound[rows, cols].Z  = point.Z ;

                    }
                }

                return layerBound;

            }
            else
            {
                return null;
            }


        }





        #endregion


        #region 内部方法

        #endregion





    }
}
